-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Cache Cover Art Calls #3015
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deployed to test.LB for in-situ testing, and it doesn't seem to be working for me.
I can see the stores in IndexedDB but it does not seem to store anything, the stores are empty, and going back and forth on two pages seems to call the CAA every time for all albums.
storeName: "coverart", | ||
}); | ||
|
||
const coverArtCacheExpiry = localforage.createInstance({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an advantage to having a separate cache instead of storing an object with {expiry : xxxx, data: yyyyy}
?
Is it to make the homemade garbage collection more efficient?
I also saw that there was a plugin for handling expiry, and they implemented it using the same DB instance but adding a separate key-value pair, the key being based on the original key.
That could be another way to do it: https://github.com/LuudJanssen/localforage-cache/blob/master/src/localforage.js#L117-L124
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe, one of the important factors of saving data in IndexedDB / LocalStorage is the cleanup process. What removeAllExpiredCacheEntries
does is run over all the keys and check if the key has been expired or not.
Saving the expiration key as ${key}_expires_${hash}
makes this process slower as we'll have to index all keys, and filter down the keys of this regex and then process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface CacheEntry {
data: string;
expiry: number
}
This approach is definitely better because a Single operation ensures data and expiry are always in sync, and makes the code simpler. BUT, when checking if data is expired, this forces you to deserialize the entire object which will increase memory usage and processing time.
OK, so I see that the issue might be between my chair and my keyboard :) I was looking at my dashboard when testing, I didn't realize this was going to apply only to the release card. I tested again, and I'm still not sure it's working as expected.
For context, checking the indexedDB after all that, I see 13 entries only |
@@ -756,13 +757,23 @@ const getAlbumArtFromReleaseGroupMBID = async ( | |||
optionalSize?: CAAThumbnailSizes | |||
): Promise<string | undefined> => { | |||
try { | |||
const cacheKey = `rag:${releaseGroupMBID}-${optionalSize}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rag? Release Art Group?
@@ -756,13 +757,23 @@ const getAlbumArtFromReleaseGroupMBID = async ( | |||
optionalSize?: CAAThumbnailSizes | |||
): Promise<string | undefined> => { | |||
try { | |||
const cacheKey = `rag:${releaseGroupMBID}-${optionalSize}`; | |||
const cachedCoverArt = await getCoverArtCache(cacheKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be applied to getAlbumArtFromListenMetadata
somewhere as well, which is used by the ListenCard component.
This PR Implements a client-side caching system for cover art using IndexedDB (with LocalStorage fallback) to improve performance and reduce server load. The system includes automatic cache expiration and cleanup mechanisms.